/*
 * The MIT License 
 *
 * Copyright (c) 2010 pf-miles
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package me.wenyue.parambinder.impl.testhelper;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import me.wenyue.parambinder.BindingContext;
import me.wenyue.parambinder.BindingParameter;
import me.wenyue.parambinder.impl.DefaultBindingContext;
import me.wenyue.parambinder.impl.SimpleParameter;
import me.wenyue.parambinder.impl.defaultbindingmethod.DefaultBindingMethodTest.Dummy;

/**
 * StaticInitUtil.java
 * 
 * @author pf-miles 2010-10-12 下午02:12:54
 * 
 */
public class StaticInitUtil {
    // primitive
    private static final int i = 1;
    // array
    private static final int[] is = new int[] { 1, 2, 3 };
    // bean
    private static Dummy bean = new Dummy();
    // collection
    private static List<Dummy> list = new ArrayList<Dummy>();

    private static final BindingParameter intParam = new SimpleParameter();
    private static final BindingParameter intArrayParam = new SimpleParameter();
    private static final BindingParameter beanParam = new SimpleParameter();
    private static final BindingParameter listParam = new SimpleParameter();
    private static final BindingParameter doubleParam = new SimpleParameter();
    private static final BindingParameter bigDecimalParam = new SimpleParameter();

    private static BindingContext context = new DefaultBindingContext();
    static {
        ((SimpleParameter) intParam).setName("intParam");
        ((SimpleParameter) intParam).setParameterClass(int.class);

        ((SimpleParameter) intArrayParam).setName("intArrayParam");
        ((SimpleParameter) intArrayParam).setParameterClass(int[].class);

        ((SimpleParameter) beanParam).setName("beanParam");
        ((SimpleParameter) beanParam).setParameterClass(Dummy.class);

        ((SimpleParameter) listParam).setName("listParam");
        ((SimpleParameter) listParam).setParameterClass(List.class);

        ((SimpleParameter) bigDecimalParam).setName("bigDecimalParam");
        ((SimpleParameter) bigDecimalParam).setParameterClass(BigDecimal.class);

        ((SimpleParameter) doubleParam).setName("doubleParam");
        ((SimpleParameter) doubleParam).setParameterClass(double.class);

        ((DefaultBindingContext) context).set("intParam", i);
        ((DefaultBindingContext) context).set("intArrayParam", is);
        ((DefaultBindingContext) context).set("beanParam", bean);
        ((DefaultBindingContext) context).set("listParam", list);
        ((DefaultBindingContext) StaticInitUtil.getContext()).set("doubleParam", doubleParam);
    }

    public static void refreshValues() {
        bean = new Dummy();
        list = new ArrayList<Dummy>();

        context = new DefaultBindingContext();
        ((SimpleParameter) intParam).setName("intParam");
        ((SimpleParameter) intParam).setParameterClass(int.class);

        ((SimpleParameter) intArrayParam).setName("intArrayParam");
        ((SimpleParameter) intArrayParam).setParameterClass(int[].class);

        ((SimpleParameter) beanParam).setName("beanParam");
        ((SimpleParameter) beanParam).setParameterClass(Dummy.class);

        ((SimpleParameter) listParam).setName("listParam");
        ((SimpleParameter) listParam).setParameterClass(List.class);

        ((SimpleParameter) bigDecimalParam).setName("bigDecimalParam");
        ((SimpleParameter) bigDecimalParam).setParameterClass(BigDecimal.class);

        ((SimpleParameter) doubleParam).setName("doubleParam");
        ((SimpleParameter) doubleParam).setParameterClass(double.class);

        ((DefaultBindingContext) context).set("intParam", i);
        ((DefaultBindingContext) context).set("intArrayParam", is);
        ((DefaultBindingContext) context).set("beanParam", bean);
        ((DefaultBindingContext) context).set("listParam", list);
        ((DefaultBindingContext) StaticInitUtil.getContext()).set("doubleParam", doubleParam);
    }

    public static int getInt() {
        return i;
    }

    public static int[] getIntArray() {
        return is;
    }

    public static Dummy getBean() {
        return bean;
    }

    public static List<Dummy> getList() {
        return list;
    }

    public static BindingParameter getIntParam() {
        return intParam;
    }

    public static BindingParameter getIntArrayParam() {
        return intArrayParam;
    }

    public static BindingParameter getBeanParam() {
        return beanParam;
    }

    public static BindingParameter getListParam() {
        return listParam;
    }

    public static BindingParameter getBigDecimalParam() {
        return bigDecimalParam;
    }

    public static BindingContext getContext() {
        return context;
    }

    public static BindingParameter getDoubleParam() {
        return doubleParam;
    }
}
